import http from '@/utils/http'
import { LoginParams, Res } from './model'
import store from '@/store'
import Cookies from 'js-cookie'

export enum Api {
  Login = '/login',
  GetUserInfo = '/sys/user/info'
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams) {
  return http.post<Res>(
    Api.Login,
    params
  )
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return http.get<Res>(Api.GetUserInfo)
}

export function clearLoginInfo () {
  Cookies.remove('token')
  store.commit('common/updateAddMenuRouters', false)
  store.dispatch('common/clearMenuState')
}

